home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Dev / ACE_SubMod.lha / wbarg.lha / WBarg.b < prev    next >
Text File  |  1994-12-30  |  8KB  |  372 lines

  1. {*
  2. ** WorkBench argument and ToolType subprograms.
  3. **
  4. ** Workbench arguments are contained in the
  5. ** WBStartup structure's ArgList after
  6. ** a program has been launched from the
  7. ** Workbench or an icon with a default tool
  8. ** has been double-clicked.
  9. **
  10. ** The order in which the arguments appear in
  11. ** the list is the same as the order in which
  12. ** the icons (corresponding to the arguments)
  13. ** were selected with the mouse.
  14.  
  15.     Wb Argument Subprograms
  16.     -----------------------
  17.   - WBlaunched returns TRUE or FALSE to indicate whether
  18.     the current program was started from the Workbench        
  19.     or not.
  20.  
  21.   - WBargcount returns the number of arguments
  22.     to a Workbench launched program. The name
  23.     of the program is NOT included in this count.        
  24.  
  25.   - WBarg$(N) returns the Nth Workbench argument
  26.     as a string. The zeroth argument is the
  27.     program's name. Only the name of the argument
  28.     is returned, not it's full path. To obtain
  29.     the latter, use WBargPath$(N).                
  30.  
  31.   - WBargPath$(N) returns the full path of the
  32.     Nth Workbench argument as a string.            
  33.  
  34.  
  35.     ToolType Subprograms
  36.     --------------------
  37.   - ToolTypeVal$(theArg$,toolType$) searches the
  38.     Wb argument's .info file for the specified tooltype
  39.     and returns its value as a string. The null string
  40.     is returned if the tooltype is not found.
  41.  
  42.   - ToolTypeValMatched(toolVal$,value$) returns
  43.     TRUE or FALSE indicating the presence or absence
  44.     of a value in a ToolType string.
  45.  
  46.   - DefaultTool$(theArg$) returns the default tool from
  47.     a Wb argument's .info file. The NULL string is returned
  48.     if no default tool exists or if the argument does not
  49.     correspond to a project icon.
  50.  
  51. ** Author: David J Benn
  52. **   Date: 25th December 1992,
  53. **        29th,30th December 1994
  54. *}
  55.  
  56. #include <stddef.h>
  57.  
  58. {*
  59. ** External references.
  60. *}
  61. EXTERNAL ADDRESS WBenchMsg    '..Task's WBStartup MESSAGE (from startup.lib)
  62.  
  63. EXTERNAL _EXIT_PROG        '..Not a variable: a main program label! Kludge!
  64.                 '..(fix this for next release of compiler)
  65. {*
  66. ** Structure definitions.
  67. *}
  68. STRUCT WBArg
  69.   ADDRESS wa_Lock
  70.   ADDRESS wa_Name
  71. END STRUCT
  72.  
  73. STRUCT Node
  74.   ADDRESS ln_Succ
  75.   ADDRESS ln_Pred
  76.   BYTE    ln_Type
  77.   BYTE    ln_Pri
  78.   ADDRESS ln_Name
  79. END STRUCT
  80.  
  81. STRUCT xMessage
  82.   Node     mn_Node
  83.   ADDRESS  mn_ReplyPort
  84.   SHORTINT mn_Length
  85. END STRUCT
  86.  
  87. STRUCT WBStartup
  88.   xMessage sm_Message
  89.   ADDRESS  sm_Process
  90.   ADDRESS  sm_Segment
  91.   LONGINT  sm_NumArgs
  92.   ADDRESS  sm_ToolWindow
  93.   ADDRESS  sm_ArgList
  94. END STRUCT
  95.  
  96. STRUCT DateStamp
  97.   LONGINT ds_Days
  98.   LONGINT ds_Minute
  99.   LONGINT ds_Tick
  100. END STRUCT
  101.  
  102. STRUCT FileInfoBlock
  103.   LONGINT   fib_DiskKey
  104.   LONGINT   fib_DirEntryType
  105.   STRING    fib_FileName SIZE 108
  106.   LONGINT   fib_Protection
  107.   LONGINT   fib_EntryType
  108.   LONGINT   fib_Size
  109.   LONGINT   fib_NumBlocks
  110.   DateStamp fib_Date
  111.   STRING    fib_Comment SIZE 80
  112.   STRING    fib_Reserved SIZE 36
  113. END STRUCT
  114.  
  115. STRUCT xGadget
  116.   ADDRESS  NextGadget
  117.   SHORTINT LeftEdge
  118.   SHORTINT TopEdge
  119.   SHORTINT Wdth
  120.   SHORTINT Height
  121.   SHORTINT Flags
  122.   SHORTINT Activation
  123.   SHORTINT GadgetType
  124.   ADDRESS  GadgetRender
  125.   ADDRESS  SelectRender
  126.   ADDRESS  GadgetText
  127.   LONGINT  MutualExclude
  128.   ADDRESS  SpecialInfo
  129.   SHORTINT GadgetID
  130.   ADDRESS  UserData
  131. END STRUCT
  132.  
  133. STRUCT DiskObject
  134.   SHORTINT do_Magic
  135.   SHORTINT do_Version
  136.   xGadget  do_Gadget
  137.   SHORTINT do_Type
  138.   ADDRESS  do_DefaultTool
  139.   ADDRESS  do_ToolTypes
  140.   LONGINT  do_CurrentX
  141.   LONGINT  do_CurrentY
  142.   ADDRESS  do_DrawerData
  143.   ADDRESS  do_ToolWindow
  144.   LONGINT  do_StackSize
  145. END STRUCT
  146.  
  147. {*
  148. ** Shared library functions used by more than one subprogram.
  149. *}
  150. DECLARE FUNCTION ADDRESS GetDiskObject(STRING theIconName) LIBRARY icon
  151. DECLARE FUNCTION FreeDiskObject(ADDRESS diskObject) LIBRARY icon
  152.  
  153. {*
  154. ** Subprogram definitions.
  155. *}
  156. SUB LONGINT WBlaunched EXTERNAL
  157.   IF WBenchMsg <> NULL THEN
  158.     WBlaunched = TRUE
  159.   ELSE
  160.     WBlaunched = FALSE
  161.   END IF
  162. END SUB
  163.  
  164. SUB SHORTINT WBargcount EXTERNAL
  165. DECLARE STRUCT WBStartup *WBinfo
  166. DECLARE STRUCT WBArg *argptr
  167. SHORTINT n
  168.  
  169.   { Return # of WB args }
  170.  
  171.   WBinfo = WBenchMsg
  172.  
  173.   IF WBinfo <> NULL THEN
  174.     n = WBinfo->sm_NumArgs
  175.     --n  '..don't include WBarg$(0)
  176.     WBargcount = n
  177.   ELSE
  178.     WBargcount = 0
  179.   END IF
  180. END SUB
  181.  
  182. SUB WBarg$(SHORTINT N) EXTERNAL
  183. DECLARE STRUCT WBStartup *WBinfo
  184. DECLARE STRUCT WBArg *argptr
  185. SHORTINT max_param,count
  186.  
  187.   { Return the Nth WB arg }
  188.  
  189.   WBinfo = WBenchMsg
  190.  
  191.   IF WBinfo <> NULL THEN
  192.     max_param = WBinfo->sm_NumArgs
  193.   ELSE
  194.     max_param = 0
  195.   END IF
  196.  
  197.   IF max_param > 0 AND N <= max_param THEN
  198.     argptr = WBinfo->sm_ArgList
  199.  
  200.     count=0
  201.     WHILE count < N
  202.       argptr = argptr+SIZEOF(WBArg)
  203.       ++count
  204.     WEND
  205.  
  206.     WBarg$ = CSTR(argptr->wa_Name)
  207.   ELSE
  208.     '..Nth argument is non-existent
  209.     WBarg$ = ""
  210.   END IF
  211. END SUB
  212.  
  213. SUB ADDRESS WBargLock(SHORTINT N)
  214. DECLARE STRUCT WBStartup *WBinfo
  215. DECLARE STRUCT WBArg *argptr
  216. SHORTINT max_param,count
  217.  
  218.   { Return the Nth WB arg lock }
  219.  
  220.   WBinfo = WBenchMsg
  221.  
  222.   IF WBinfo <> NULL THEN
  223.     max_param = WBinfo->sm_NumArgs
  224.   ELSE
  225.     max_param = 0
  226.   END IF
  227.  
  228.   IF max_param > 0 AND N <= max_param THEN
  229.     argptr = WBinfo->sm_ArgList
  230.  
  231.     count=0
  232.     WHILE count < N
  233.       argptr = argptr+SIZEOF(WBArg)
  234.       ++count
  235.     WEND
  236.  
  237.     WBargLock = argptr->wa_Lock
  238.   ELSE
  239.     '..Nth lock is non-existent
  240.     WBargLock = NULL
  241.   END IF
  242. END SUB
  243.  
  244. SUB get_abs_path(ADDRESS lock, ADDRESS abspathaddr)
  245. STRING abspath ADDRESS abspathaddr
  246. ADDRESS parentlock
  247. DECLARE STRUCT FileInfoBlock info
  248.  
  249. DECLARE FUNCTION ADDRESS ParentDir LIBRARY dos
  250. DECLARE FUNCTION Examine LIBRARY dos
  251.  
  252.   { recursively construct absolute path }
  253.  
  254.   IF lock <> NULL THEN
  255.     parentlock = ParentDir(lock)
  256.     get_abs_path(parentlock,abspathaddr)
  257.   END IF
  258.  
  259.   IF lock <> NULL THEN
  260.     Examine(lock,info)
  261.     abspath = abspath + info->fib_FileName
  262.     IF parentlock <> NULL THEN
  263.       '..directory
  264.       abspath = abspath + "/"
  265.     ELSE
  266.       '..volume
  267.       abspath = abspath + ":"
  268.     END IF
  269.   END IF
  270. END SUB
  271.  
  272. SUB WBargPath$(SHORTINT N) EXTERNAL
  273. ADDRESS arglock
  274. STRING  abspath
  275.  
  276.   { Return full path of Nth WB arg }
  277.  
  278.   arglock = WBargLock(N)
  279.  
  280.   IF arglock <> NULL THEN
  281.     get_abs_path(arglock,@abspath)
  282.     WBargPath$ = abspath
  283.   ELSE
  284.     WBargPath$ = ""
  285.   END IF
  286. END SUB
  287.  
  288. SUB ToolTypeVal$(theArg$,toolType$) EXTERNAL
  289. DECLARE STRUCT DiskObject *dobj
  290. ADDRESS toolArray, toolTypeValAddr
  291.  
  292. DECLARE FUNCTION ADDRESS FindToolType(ADDRESS toolArray, STRING toolType) LIBRARY icon
  293.  
  294.   { Return a tooltype value from a Wb argument's .info file }
  295.  
  296.   LIBRARY "icon.library"
  297.  
  298.   IF theArg$ <> "" THEN
  299.     dobj = GetDiskObject(theArg$)
  300.     IF dobj = NULL THEN
  301.         tmpVal$ = ""
  302.     ELSE
  303.         toolArray = dobj->do_ToolTypes
  304.         IF toolArray = NULL THEN
  305.       tmpVal$ = ""
  306.         ELSE
  307.           toolTypeValAddr = FindToolType(toolArray,toolType$)
  308.        IF toolTypeValAddr = NULL THEN
  309.         tmpVal$ = ""
  310.       ELSE
  311.         tmpVal$ = CSTR(toolTypeValAddr)
  312.       END IF
  313.      END IF
  314.     END IF
  315.  
  316.     IF dobj <> NULL THEN CALL FreeDiskObject(dobj)
  317.   ELSE
  318.     '..Wb argument is NULL.
  319.     tmpVal$ = ""
  320.   END IF
  321.  
  322.   LIBRARY CLOSE "icon.library"
  323.  
  324.   ToolTypeVal$ = tmpVal$
  325. END SUB
  326.  
  327. SUB LONGINT ToolTypeValMatched(toolVal$,value$) EXTERNAL
  328. LONGINT theVal
  329.  
  330. DECLARE FUNCTION SHORTINT MatchToolValue(toolVal$,value$) LIBRARY icon
  331.  
  332.   { Return TRUE/FALSE indicating presence/absence of value in ToolType string }
  333.  
  334.   LIBRARY "icon.library"
  335.  
  336.   theVal = -MatchToolValue(toolVal$,value$)
  337.  
  338.   LIBRARY CLOSE "icon.library"
  339.  
  340.   ToolTypeValMatched = theVal
  341. END SUB
  342.  
  343. SUB DefaultTool$(theArg$) EXTERNAL
  344. DECLARE STRUCT DiskObject *dobj
  345.  
  346.   { Return the default tool from a Wb argument's .info file }
  347.  
  348.   LIBRARY "icon.library"
  349.  
  350.   IF theArg$ <> "" THEN
  351.     dobj = GetDiskObject(theArg$)
  352.     IF dobj = NULL THEN
  353.         tmpVal$ = ""
  354.     ELSE
  355.         IF dobj->do_DefaultTool = NULL THEN
  356.       tmpVal$ = ""
  357.         ELSE
  358.       tmpVal$ = CSTR(dobj->do_DefaultTool)
  359.      END IF
  360.     END IF
  361.  
  362.     IF dobj <> NULL THEN CALL FreeDiskObject(dobj)
  363.   ELSE
  364.     '..Wb argument is NULL.
  365.     tmpVal$ = ""
  366.   END IF
  367.  
  368.   LIBRARY CLOSE "icon.library"
  369.  
  370.   DefaultTool$ = tmpVal$
  371. END SUB
  372.